#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "lv_port.h"
#include "lvgl.h"
#include "lv_demos.h"
#include "st7789_i80.h"
#include "driver/i2s_std.h"
#include "xl9555.h"

#define LCD_RST_IO           IO1_3
#define LCD_BL_IO            IO1_2
#define TP_RST_IO            IO1_0

#define XL9555_SDA  GPIO_NUM_10
#define XL9555_SCL  GPIO_NUM_11

void i2c_and_xl9555_init(void)
{
    xl9555_init(XL9555_SDA,XL9555_SCL,GPIO_NUM_NC,NULL);
    xl9555_ioconfig((~(LCD_RST_IO | LCD_BL_IO | TP_RST_IO))&0xFFFF);

}

void app_task(void* param)
{
    i2c_and_xl9555_init();          //初始化XL9555
    st7789_i80_lcd_backlight(true);         //打开背光
    lv_port_init();                 //初始化LVGL
    lv_demo_widgets();              //初始化控件demo程序
    //lv_demo_stress();
    //vTaskDelay(pdMS_TO_TICKS(200));
    while(1)
    {
        vTaskDelay(1);
        lv_task_handler();          //LVGL循环处理
    }
    vTaskDelete(NULL);
    return;
}

// 主函数
void app_main(void)
{
    xTaskCreatePinnedToCore(app_task,"app2",8192,NULL,5,NULL,1);
}
